package com.ws.simplegame;

import com.ws.simplegame.R;
import com.ws.simplegame.KrestikinolikiModel;
import android.widget.Button;

public class KrestikinolikiController {
	
	private static KrestikinolikiController instance;

	private KrestikinolikiController() {
	}

	public static synchronized KrestikinolikiController getInstance() {
		if (instance == null)
			instance = new KrestikinolikiController();
		return instance;
	} 

	private static KrestikinolikiModel model = KrestikinolikiModel.getInstance();

	private Button[] buttons;

	private void drawButton(Button btn, int state) {
		if ( KrestikinolikiModel.NOUGHT == state)
			btn.setBackgroundResource(R.drawable.o);
		else if (KrestikinolikiModel.CROSS == state)
			btn.setBackgroundResource(R.drawable.x);
		else
			btn.setBackgroundResource(R.drawable.clear);
	}

	public void refreshGame() {
		for (int i = 0; i < buttons.length; i++)
			drawButton(buttons[i], model.getGameField()[i / 3][i % 3]);
	}

	public void setButtons(Button[] buttons) {
		this.buttons = buttons;
	}
}
